#include "SDLProgressBar.h"

using namespace sdl;

SDLProgressBar::SDLProgressBar(SDLSurface* surface) : sdlSurface(surface), x(0), y(0), width(0), height(0)
{
	progressMonitor = 0;
	borderColor = 0;
	backgroundColor = 0;
	foregroundColor = 0;
}

SDLProgressBar::SDLProgressBar(SDLProgressMonitor* monitor, SDLSurface* surface) : sdlSurface(surface), x(0), y(0), width(0), height(0)
{
	progressMonitor = monitor;
	borderColor = 0;
	backgroundColor = 0;
	foregroundColor = 0;
}

SDLProgressBar::~SDLProgressBar(void)
{
	delete borderColor;
	delete backgroundColor;
	delete foregroundColor;
	delete progressMonitor;
}

void SDLProgressBar::setX(int x)
{
	this->x = x;
}

int SDLProgressBar::getX(void)
{
	return x;
}

void SDLProgressBar::setY(int y)
{
	this->y = y;
}

int SDLProgressBar::getY(void)
{
	return y;
}

void SDLProgressBar::setWidth(int width)
{
	this->width = width;
}

int SDLProgressBar::getWidth(void)
{
	return width;
}

void SDLProgressBar::setHeight(int height)
{
	this->height = height;
}

int SDLProgressBar::getHeight(void)
{
	return height;
}

void SDLProgressBar::setBorderColor(Color* color)
{
	borderColor = color;
}

void SDLProgressBar::setBackgroundColor(Color* color)
{
	backgroundColor = color;
}

void SDLProgressBar::setForegroundColor(Color* color)
{
	foregroundColor = color;
}

void SDLProgressBar::draw(void)
{
	int progressWidth = 0;
	if (progressMonitor->getProgress() == progressMonitor->getMaximumProgress())
	{
		progressWidth = width;
	}
	else if (progressMonitor->getProgress() > 0)
	{
		progressWidth = progressMonitor->getProgress()*width/progressMonitor->getMaximumProgress();
	}
	boxRGBA(sdlSurface->getSurface(), x, y, x+width, y+height, borderColor->getRed(),
		borderColor->getGreen(), borderColor->getBlue(), borderColor->getAlpha());
	boxRGBA(sdlSurface->getSurface(), x+1, y+1, x+width-1, y+height-1, backgroundColor->getRed(),
		backgroundColor->getGreen(), backgroundColor->getBlue(), backgroundColor->getAlpha());
	boxRGBA(sdlSurface->getSurface(), x+2, y+2, x+progressWidth-2, y+height-2, foregroundColor->getRed(),
		foregroundColor->getGreen(), foregroundColor->getBlue(), foregroundColor->getAlpha());
}
